namespace InventoryManagement
{
	using System;
	using System.Collections;
	using System.Collections.Generic;
	using System.ComponentModel;
	using System.Data;
	using System.Data.SqlClient;
	using System.Text;
	
	
	public class Pick_Up : BaseTable
	{
		
		#region Static SQL String Members
		/// <remarks>This field represents the full SELECT string for the table Pick Up, with the WHERE clause.</remarks>
		internal static string _SQL_Select = "SELECT [ID], [ID_WorkOrder], [Item], [Quantity], [SerialNumber], [Accessories] FROM [dbo].[Pick Up] WHERE [ID]=@ID ";
		
		/// <remarks>This field represents the full SELECT string for the table Pick Up, with the WHERE clause.</remarks>
		internal static string _SQL_SelectByParam = @"SELECT [ID], [ID_WorkOrder], [Item], [Quantity], [SerialNumber], [Accessories] FROM [dbo].[Pick Up] WHERE isnull(convert(varchar(36),[ID]),'true')=isnull(convert(varchar(36),@ID),isnull(convert(varchar(36),[ID]),'true')) AND isnull(convert(varchar(36),[ID_WorkOrder]),'true')=isnull(convert(varchar(36),@ID_WorkOrder),isnull(convert(varchar(36),[ID_WorkOrder]),'true')) AND isnull(convert(varchar,[Item]),'true')=isnull(convert(varchar,@Item),isnull(convert(varchar,[Item]),'true')) AND isnull(convert(varchar,[Quantity]),'true')=isnull(convert(varchar,@Quantity),isnull(convert(varchar,[Quantity]),'true')) AND isnull(convert(varchar,[SerialNumber]),'true')=isnull(convert(varchar,@SerialNumber),isnull(convert(varchar,[SerialNumber]),'true')) AND isnull(convert(varchar,[Accessories]),'true')=isnull(convert(varchar,@Accessories),isnull(convert(varchar,[Accessories]),'true')) ";
		
		/// <remarks>This field represents the full INSERT INTO string for the table Pick Up.</remarks>
		internal static string _SQL_Insert = "INSERT INTO [dbo].[Pick Up] ([ID], [ID_WorkOrder], [Item], [Quantity], [SerialNumber], [Accessories]) VALUES(@ID, @ID_WorkOrder, @Item, @Quantity, @SerialNumber, @Accessories) ";
		
		/// <remarks>This field represents the full UPDATE string for the table Pick Up, with the WHERE clause.</remarks>
		internal static string _SQL_Update = "UPDATE [dbo].[Pick Up] SET [ID] = @ID, [ID_WorkOrder] = @ID_WorkOrder, [Item] = @Item, [Quantity] = @Quantity, [SerialNumber] = @SerialNumber, [Accessories] = @Accessories WHERE [ID]=@ID ";
		
		/// <remarks>This field represents the DELETE string for the table Pick Up, with the WHERE clause.</remarks>
		internal static string _SQL_Delete = "DELETE FROM [dbo].[Pick Up] WHERE [ID]=@ID ";
		#endregion
		
		#region Tables Members
		/// <remarks>SQL Type:uniqueidentifier - </remarks>
		private System.Nullable<System.Guid> _ID;
		
		[DisplayName("ID")]
		[Category("Primary Key")]
		public System.Nullable<System.Guid> ID
		{
			get
			{
				try
				{
					return _ID;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting ID", err);
				}
			}
			set
			{
				try
				{
					_ID = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting ID", err);
				}
			}
		}
		
		/// <remarks>SQL Type:uniqueidentifier - </remarks>
		private System.Nullable<System.Guid> _ID_WorkOrder;
		
		[DisplayName("ID_Work Order")]
		[Category("Foreign Key")]
		public System.Nullable<System.Guid> ID_WorkOrder
		{
			get
			{
				try
				{
					return _ID_WorkOrder;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting ID_WorkOrder", err);
				}
			}
			set
			{
				try
				{
					_ID_WorkOrder = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting ID_WorkOrder", err);
				}
			}
		}
		
		/// <remarks>SQL Type:varchar - </remarks>
		private string _Item;
		
		[DisplayName("Item")]
		[Category("Column")]
		public string Item
		{
			get
			{
				try
				{
					return _Item;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting Item", err);
				}
			}
			set
			{
				try
				{
					if ((value.Length <= 200))
					{
						_Item = value;
					}
					else
					{
						throw new OverflowException("Error setting Item, Length of value is to long. Maximum Length: 200");
					}
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting Item", err);
				}
			}
		}
		
		/// <remarks>SQL Type:int - </remarks>
		private System.Nullable<int> _Quantity;
		
		[DisplayName("Quantity")]
		[Category("Column")]
		public System.Nullable<int> Quantity
		{
			get
			{
				try
				{
					return _Quantity;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting Quantity", err);
				}
			}
			set
			{
				try
				{
					_Quantity = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting Quantity", err);
				}
			}
		}
		
		/// <remarks>SQL Type:varchar - </remarks>
		private string _SerialNumber;
		
		[DisplayName("Serial Number")]
		[Category("Column")]
		public string SerialNumber
		{
			get
			{
				try
				{
					return _SerialNumber;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting SerialNumber", err);
				}
			}
			set
			{
				try
				{
					if ((value.Length <= 200))
					{
						_SerialNumber = value;
					}
					else
					{
						throw new OverflowException("Error setting SerialNumber, Length of value is to long. Maximum Length: 200");
					}
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting SerialNumber", err);
				}
			}
		}
		
		/// <remarks>SQL Type:varchar - </remarks>
		private string _Accessories;
		
		[DisplayName("Accessories")]
		[Category("Column")]
		public string Accessories
		{
			get
			{
				try
				{
					return _Accessories;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting Accessories", err);
				}
			}
			set
			{
				try
				{
					if ((value.Length <= 200))
					{
						_Accessories = value;
					}
					else
					{
						throw new OverflowException("Error setting Accessories, Length of value is to long. Maximum Length: 200");
					}
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting Accessories", err);
				}
			}
		}
		#endregion
		
		#region Related Objects
		/// <remarks>Represents the foreign key object</remarks>
		private Work_Order _ID_WorkOrder_Work_Order;
		
		[Description("Represents the foreign key object of the type Work_Order")]
		public Work_Order ID_WorkOrder_Work_Order
		{
			get
			{
				try
				{
					return _ID_WorkOrder_Work_Order;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting ID_WorkOrder_Work_Order", err);
				}
			}
			set
			{
				try
				{
					_ID_WorkOrder_Work_Order = value;
					_ID_WorkOrder = _ID_WorkOrder_Work_Order.ID;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting ID_WorkOrder_Work_Order", err);
				}
			}
		}
		#endregion
		
		#region Public Methods
		public void Select()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Pick_Up._SQL_Select;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				SqlDataReader rs = Com.ExecuteReader();
				while(rs.Read())
				{
					AddFromRecordSet(rs);
				}
				rs.Close();
				Conn.Close();
				rs.Dispose();
				Com.Dispose();
				Conn.Dispose();
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public System.Data.DataTable SelectByParam()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Pick_Up._SQL_SelectByParam;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				SqlDataAdapter objDataAdapter = new SqlDataAdapter(Com);
				DataTable objDataTable = new DataTable();
				objDataAdapter.Fill(objDataTable);
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return objDataTable;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public int Insert()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Pick_Up._SQL_Insert;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				int rowseffected = Com.ExecuteNonQuery();
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return rowseffected;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public int Update()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Pick_Up._SQL_Update;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				int rowseffected = Com.ExecuteNonQuery();
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return rowseffected;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public int Delete()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Pick_Up._SQL_Delete;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				int rowseffected = Com.ExecuteNonQuery();
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return rowseffected;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public string[] GetSqlCommandStrings()
		{
			try
			{
				string[] CommStr = new string[4];
				CommStr[0] = "SELECT [ID], [ID_WorkOrder], [Item], [Quantity], [SerialNumber], [Accessories] FROM [dbo].[Pick Up] WHERE [ID] = " + _ID + "";
				CommStr[1] = "INSERT INTO [dbo].[Pick Up] ([ID], [ID_WorkOrder], [Item], [Quantity], [SerialNumber], [Accessories]) VALUES(" + _ID + ", " + _ID_WorkOrder + ", '" + _Item.Replace("'","''") + "', " + _Quantity + ", '" + _SerialNumber.Replace("'","''") + "', '" + _Accessories.Replace("'","''") + "')";
				CommStr[2] = "UPDATE [dbo].[Pick Up] SET [ID_WorkOrder] = " + _ID_WorkOrder + " ,[Item] = '" + _Item.Replace("'","''") + "' ,[Quantity] = " + _Quantity + " ,[SerialNumber] = '" + _SerialNumber.Replace("'","''") + "' ,[Accessories] = '" + _Accessories.Replace("'","''") + "' WHERE [ID] = " + _ID + "";
				CommStr[3] = "DELETE FROM [dbo].[Pick Up] WHERE [ID] = " + _ID + "";
				return CommStr;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		#endregion
		
		#region Private Methods
		private void AddFromRecordSet(SqlDataReader rs)
		{
			try
			{
				// if value from the recordset, to the ID field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("ID")) == false))
				{
					ID = rs.GetGuid(rs.GetOrdinal("ID"));
				}
				// if value from the recordset, to the ID_WorkOrder field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("ID_WorkOrder")) == false))
				{
					ID_WorkOrder = rs.GetGuid(rs.GetOrdinal("ID_WorkOrder"));
				}
				// if value from the recordset, to the Item field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("Item")) == false))
				{
					Item = rs.GetString(rs.GetOrdinal("Item"));
				}
				// if value from the recordset, to the Quantity field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("Quantity")) == false))
				{
					Quantity = rs.GetInt32(rs.GetOrdinal("Quantity"));
				}
				// if value from the recordset, to the SerialNumber field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("SerialNumber")) == false))
				{
					SerialNumber = rs.GetString(rs.GetOrdinal("SerialNumber"));
				}
				// if value from the recordset, to the Accessories field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("Accessories")) == false))
				{
					Accessories = rs.GetString(rs.GetOrdinal("Accessories"));
				}
			}
			catch (SqlException sqlExc)
			{
				throw sqlExc;
			}
			catch (Exception Exc)
			{
				throw Exc;
			}
		}
		
		private SqlParameter[] GetSqlParameters()
		{
			List<SqlParameter> SqlParmColl = new List<SqlParameter>();
			try
			{
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@ID", ID, SqlDbType.UniqueIdentifier));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@ID_WorkOrder", ID_WorkOrder, SqlDbType.UniqueIdentifier));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@Item", Item, SqlDbType.VarChar));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@Quantity", Quantity, SqlDbType.Int));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@SerialNumber", SerialNumber, SqlDbType.VarChar));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@Accessories", Accessories, SqlDbType.VarChar));
				return SqlParmColl.ToArray();
			}
			catch (Exception Exc)
			{
				throw Exc;
			}
		}
		#endregion
	}
	
	public class Pick_UpCollection : System.Collections.CollectionBase
	{
		
		[Description("Adds a new Pick_Up to the collection.")]
		public int Add(Pick_Up item)
		{
			int newindex = List.Add(item);
			return newindex;
		}
		
		[Description("Removes a Pick_Up from the collection.")]
		public void Remove(Pick_Up item)
		{
			List.Remove(item);
		}
		
		[Description("Inserts an Pick_Up into the collection at the specified index.")]
		public void Insert(int index, Pick_Up item)
		{
			List.Insert(index, item);
		}
		
		[Description("Returns the index value of the Pick_Up class in the collection.")]
		public int IndexOf(Pick_Up item)
		{
			return List.IndexOf(item);
		}
		
		[Description("Returns true if the Pick_Up class is present in the collection.")]
		public bool Contains(Pick_Up item)
		{
			return List.Contains(item);
		}
	}
	
	public enum Pick_Up_Fields
	{
		
		ID,
		
		ID_WorkOrder,
		
		Item,
		
		Quantity,
		
		SerialNumber,
		
		Accessories,
	}
}
